<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=path %>/layui/css/layui.css">
  <link rel="stylesheet" href="<%=path %>/layui/css/lxq.css">
	<script type="text/javascript" src="<%=path %>/layui/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path %>/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path %>/layui/util.js" charset="utf-8"></script>
</head>
<body>
<div class="lxq-body">
	<div class="layui-row lxq-address">
		位置：系统管理>用户管理
		<hr>
	</div>

	 <form class="layui-form"  method="post" id="searchForm">
	<div class="layui-row lxq-search" >
		<div class="data-search">
		  搜索ID：
		  <div class="layui-inline">
		    <input class="layui-input" name="userId" id="userId" autocomplete="off">
		  </div>
		  学院：
		  <div class="layui-inline">
		     <select id="userAcademy" name="userAcademyId" lay-filter="userAcademy" lay-search></select>
		  </div>
		   专业：
		  <div class="layui-inline">
		    <select id="userMajor" name="userMajorId" lay-filter="userMajor" lay-search></select>
		  </div>
		  班级：
		  <div class="layui-inline">
		     <select id="userClass" name="userClassId" lay-filter="userClass" lay-search></select>
		  </div>
		  部门：
		  <div class="layui-inline">
		     <select id="userUnit" name="userUnitId" lay-filter="userUnit" lay-search></select>
		  </div>
		  <button class="layui-btn" lay-submit lay-filter="search">搜索</button>
		  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
		</div>
	</div>
</form>

 	<div class="layui-row lxq-form">
 	
 		<table class="layui-hide" id="data_form" lay-filter="main"></table> 
 	
 	</div>

</div>              
          

 
<script>
layui.use(['table','form'], function(){
  var table = layui.table;
  var form = layui.form;
  
  getAcademy();
  getMajor("");
  getClass("");
  getUnit("");
  
  form.on('select(userAcademy)', function(data){
	  getMajor(data.value);
	  getUnit(data.value);
	});    
  form.on('select(userMajor)', function(data){
	  getClass(data.value);
	}); 
  
  table.render({
	    elem: '#data_form'
	    ,url:'<%=path %>/biz/SysUser_list'
	    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
	    ,toolbar: '#toolbarDemo'
	    ,page: true
	    ,cols: [[
		   {type: 'checkbox', fixed: 'left'}
	      ,{field:'userId',  title: 'ID', sort: true}
	      ,{field:'userName',  title: '姓名'}
	      ,{field:'userType', title: '用户类型', templet:'<div>{{ Situation(d.userType,"0,1,9","学生,教师,管理员")}}</div>'}
	      ,{field:'userAcademy', title: '学院'}
	      ,{field:'userMajor', title: '专业'}
	      ,{field:'userClass', title: '班级'}
	      ,{field:'userUnit', title: '部门'}
	      ,{fixed: 'right', title:'操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
 		 ,id: 'data_form'
	  });
  
   
	  form.on('submit(search)', function(data){
	      table.reload("data_form",{
	    	  url:'<%=basePath %>/biz/SysUser_list'
	    	  ,where: data.field
	          ,page: {
	            curr: 1 //重新从第 1 页开始
	          }
	      });
	
		  return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
  
  
	  //监听工具条
	  table.on('tool(main)', function(obj){
	    var data = obj.data;
	    if(obj.event === 'detail'){
	    	  layer.open({
	    		  title: '用户详情',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=path %>/biz/SysUser_toDetail'
	    	  });
	    } else if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
	        obj.del();
	        $.post('<%=path %>/biz/SysUser_del',{"id":data.id},function(){});
	        layer.close(index);
	      });
	    } else if(obj.event === 'edit'){
	    	  layer.open({
	    		  title: '修改用户信息',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=path %>/biz/SysUser_toEdit'
	    	  });
	    }
	  });
  
  		
	  //头工具栏事件
	  table.on('toolbar(main)', function(obj){
	    var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	      case 'add':
	    	  layer.open({
	    		  title: '添加页面',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=path %>/biz/SysUser_toAdd'
	    	  });
	      break;
	      case 'getCheckLength':
	        var data = checkStatus.data;
	        layer.msg('选中了：'+ data.length + ' 个');
	      break;
	      case 'isAll':
	        layer.msg(checkStatus.isAll ? '全选': '未全选');
	      break;
	    };
	  });
	  
	  function getAcademy(){
		  $.ajax({
				type:"post",
				url:"<%=basePath%>/biz/Info_getList",
				data:{level : "1"},
				success:function(data){
					$("#userAcademy").find("option").remove();
					$("#userAcademy").append("<option value=''>请选择学院</option>");
					for(var i = 0; i < data.length; i++){
						$("#userAcademy").append("<option value='"+data[i].id+"'>"+data[i].infoName+"</option>");
					}
					form.render('select');
					getMajor(data[0].id+"");
					getUnit(data[0].id+"");
				}
		  });
	}


	function getMajor(parent){
		  $.ajax({
				type:"post",
				url:"<%=basePath%>/biz/Info_getList",
				data:{level : "2" , infoParent : parent},
				success:function(data){
					$("#userMajor").find("option").remove();
					$("#userMajor").append("<option value=''>请选择专业</option>");
					for(var i = 0; i < data.length; i++){
						$("#userMajor").append("<option value='"+data[i].id+"'>"+data[i].infoName+"</option>");
						
					}
					form.render('select');
					getClass(data[0].id+"");
				}
		  });
	}

	function getClass(parent){
		  $.ajax({
				type:"post",
				url:"<%=basePath%>/biz/Info_getList",
				data:{level : "3" , infoParent : parent},
				success:function(data){
					$("#userClass").find("option").remove();
					$("#userClass").append("<option value=''>请选择班级</option>");
					for(var i = 0; i < data.length; i++){
						$("#userClass").append("<option value='"+data[i].id+"'>"+data[i].infoName+"</option>");
						
					}
					form.render('select');
					
				}
		  });
	}

	function getUnit(parent){
		  $.ajax({
				type:"post",
				url:"<%=basePath%>/biz/Info_getList",
				data:{level : "4" , infoParent : parent},
				success:function(data){
					$("#userUnit").find("option").remove();
					$("#userUnit").append("<option value=''>请选择部门</option>");
					for(var i = 0; i < data.length; i++){
						$("#userUnit").append("<option value='"+data[i].id+"'>"+data[i].infoName+"</option>");
						
					}
					form.render('select');
					
				}
		  });
	}
	  
	  
  var active = {
		    reload: function(){
		      var searchId = $('#search_id');
		      table.reload("data_form",{
		    	  url:'<%=path %>/biz/SysUser_list'
		    	  ,where: {
		    		  userId: searchId.val()
		    	  }
		          ,page: {
		            curr: 1 //重新从第 1 页开始
		          }
		      });
		      //执行重载
		    }
  
		  };
		  
		  $('.data-search .layui-btn').on('click', function(){
		    var type = $(this).data('type');
		    active[type] ? active[type].call(this) : '';
		  });

  
});
</script>



    <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>

  </div>
</script>
</body>
</html>